package com.huxin.servelt;

import com.alibaba.fastjson.JSON;
import com.huxin.pojo.UserInfo;
import com.huxin.service.Userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user/updateById")
public class UserUpdateByIdServlet extends HttpServlet {
    private Userservice userservice=new Userservice();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //从session中获取aid todo
        Integer aid = (Integer) req.getSession().getAttribute("userId");

        //获取前端传过来的账号 密码 验证码
        String s = req.getReader().readLine();
        UserInfo userInfo = JSON.parseObject(s, UserInfo.class);
        userInfo.setAid(aid);
        System.out.println("修改用户信息:"+userInfo);
        int i=userservice.updateById(userInfo);
        resp.getWriter().write(String.valueOf(i));


    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
